package com.itcast.demo13;



import java.util.*;

public class Demo01 {
    public static void main(String[] args) {
        List<Student> studentList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        Student stu = null;
        for (int i = 0; i < 10 ; i++) {
            int month = new Random().nextInt(12);
            int day = new Random().nextInt(28);
            int local = new Random().nextInt(5);
            calendar.set(2020,month,day);
            Date birthday = calendar.getTime();
            stu = new Student(i,"同学座位"+local,birthday);
            studentList.add(stu);
        }
        method(studentList);
    }

    private static void method(List<Student> list) {
        Map<String, com.Itheima.demo13.Student> map = new HashMap<>();
        for (Student student : list) {
            if(map.containsKey(student.getZuo())){
                Student oldstudent = map.get(student.getZuo());
                if(oldstudent.getBrithday().compareTo(student.getBrithday())<0){
                    map.put(student.getZuo(),student);
                }
                 }else{
                map.put(student.getZuo(),student);
            }
        }
        System.out.println(map);
        System.out.println(map.size());
    }

}
